<?php
/*
 * Created on 20.12.2005
 *
 */
 
m2import('phpinchains/Filter.php');


/**
 * For use of this filter a config var 'actionParamId' has to be provided 
 * 
 * To programmatically override the action use $GLOBALS['actionOverride'].
 * 
 */
class QueryStringActionParamFilter extends phpinchains_Filter
{
    
    var $actionParamId;
    var $moduleParamId;

    function init (& $config) {
    	$this->config = $config;
        $this->actionParamId = $config['actionParamId'];
        $this->moduleParamId = $config['moduleParamId'];
        $this->mediumParamId = $config['mediumParamId'];
    }

    function doFilter (& $env, & $chain) {
        if (isset($this->config['action']))
            $env->setZombie('__actionParam__', $this->config['action']);
        elseif ($GLOBALS['actionOverride'])
            $env->setZombie('__actionParam__', $GLOBALS['actionOverride']);
        else
            $env->setZombie('__actionParam__', $env->param($this->actionParamId));
        if (isset($this->config['medium']))
        {
            $env->setZombie('__mediumParam__', $this->config['medium']);
        } elseif ($env->param($this->mediumParamId)) {
            $env->setZombie('__mediumParam__', $env->param($this->mediumParamId));
        } else {
            $env->setZombie('__mediumParam__', "html");
        }
        $run = &phpinchains_RuntimeConfig::getInstance();
        if ($this->moduleParamId)
        {            
            $run->set('moduleParam', $env->param($this->moduleParamId));
            $run->set('moduleParamId', $this->moduleParamId);
        }
        $run->set("actionParam", "queryString");
        $run->set("actionParamId", $this->actionParamId);
        $chain->doFilter($env);
    }

}


?>
